//
//  LogView.m
//  zijinlian
//
//  Created by lzy on 2017/3/7.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "LogView.h"
#import "ZJButton.h"

@implementation LogView

-(id)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        CGFloat height=30;
        self.backgroundColor=RGB(246, 246, 246);
        [self addSubview:self.headView];
        [self addSubview:self.IDLab];
        [self addSubview:self.pswLab];
        [self addSubview:self.logBtn];
        [self addSubview:self.lineLab];
        [self addSubview:self.findpswBtn];
        [self addSubview:self.LogonlineLab];
        [self addSubview:self.weiChatBtn];
        [self addSubview:self.qqBtn];
        [self addSubview:self.IDimageView];
        [self addSubview:self.PSWimageView];
        [self addSubview:self.IDTF];
        [self addSubview:self.pswTF];
        [self addSubview:self.view];
        [self.view addSubview:self.imag];
        [self.view addSubview:self.CheckNum];
        [self.view addSubview:self.CheckImg];
        [self.view addSubview:self.CheckBtn];
        self.view.hidden=YES;
        //眼睛
        _eyeBtn=[MYUI creatButtonFrame:CGRectMake(MainW-35, 128+60+6, 25, 15) setBackgroundImage:[UIImage imageNamed:@"icon_eye_nor"]];
        [_eyeBtn addTarget:self action:@selector(eyeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:self.eyeBtn];
        
        [_logBtn makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(self.pswLab.mas_bottom).offset(height);
            make.left.equalTo(self.mas_left).offset(10);
            make.right.equalTo(self.mas_right).offset(-10);
            make.height.equalTo(98/2);
        }];
        NSUserDefaults*defaults=[NSUserDefaults standardUserDefaults];
        NSString*lang=[defaults objectForKey:@"Language"];
        if ([lang isEqualToString:@"藏文"]) {
            [_findpswBtn makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.logBtn.mas_bottom).offset(10);
                make.right.equalTo(-10);
                make.width.equalTo(80);
                make.height.equalTo(20);
            }];
        }else{
            [_findpswBtn makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.logBtn.mas_bottom).offset(10);
                make.right.equalTo(-10);
                make.width.equalTo(60);
                make.height.equalTo(20);
            }];
        }
        
        [_lineLab makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.findpswBtn.mas_bottom).offset(30);
            make.left.equalTo(self.mas_left).offset(10);
            make.right.equalTo(self.mas_right).offset(-10);
            make.height.equalTo(1);
        }];
        [_LogonlineLab makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_lineLab.mas_centerY);
            make.centerX.equalTo(_lineLab.mas_centerX);
            make.width.equalTo(112);
            make.height.equalTo(15);
        }];
        [_weiChatBtn makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.centerX).offset(-30);
            make.top.equalTo(self.LogonlineLab.mas_bottom).offset(15);
            //make.left.equalTo(self.left).offset(10);
            make.width.equalTo(46);
            make.height.equalTo(46);
        }];
        [_qqBtn makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.centerX).offset(30);
            make.top.equalTo(self.LogonlineLab.mas_bottom).offset(15);
            //make.left.equalTo(self.left).offset(10);
            make.width.equalTo(46);
            make.height.equalTo(46);
        }];
        NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
        //添加当前类对象为一个观察者，name和object设置为nil，表示接收一切通知
        [center addObserver:self selector:@selector(notice) name:@"123" object:nil];
       
    }
    return self;
}
-(void)notice{
    self.view.hidden=NO;
    [_logBtn makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(322);
        make.left.equalTo(self.left).offset(10);
        make.right.equalTo(self.right).offset(-10);
        make.height.equalTo(98/2);
    }];
    [_findpswBtn makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.logBtn.bottom).offset(10);
        make.right.equalTo(-10);
        make.width.equalTo(60);
        make.height.equalTo(20);
    }];
    [_lineLab makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.findpswBtn.bottom).offset(30);
        make.left.equalTo(self.left).offset(10);
        make.right.equalTo(self.right).offset(-10);
        make.height.equalTo(1);
    }];
    [_LogonlineLab makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_lineLab.mas_centerY);
        make.centerX.equalTo(_lineLab.mas_centerX);
        make.width.equalTo(112);
        make.height.equalTo(15);
    }];
    [_weiChatBtn makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.centerX).offset(-30);
        make.top.equalTo(self.LogonlineLab.mas_bottom).offset(15);
        //make.left.equalTo(self.left).offset(10);
        make.width.equalTo(46);
        make.height.equalTo(46);
    }];
    [_qqBtn makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.centerX).offset(30);
        make.top.equalTo(self.LogonlineLab.mas_bottom).offset(15);
        //make.left.equalTo(self.left).offset(10);
        make.width.equalTo(46);
        make.height.equalTo(46);
    }];

}
-(void)eyeBtnClick:(UIButton *)btn
{
    if (self.pswTF.secureTextEntry==YES) {
        [btn setBackgroundImage:[UIImage imageNamed:@"icon_eye_pre"] forState:UIControlStateNormal];
    }else{
         [btn setBackgroundImage:[UIImage imageNamed:@"icon_eye_nor"] forState:UIControlStateNormal];
    }
    if (_delegete && [_delegete respondsToSelector:@selector(eyeAndOpen:)]) {
        [_delegete eyeAndOpen:self.pswTF.secureTextEntry];
    }
}
-(UIImageView *)headView
{
    if (!_headView) {
        _headView=[[UIImageView alloc]initWithFrame:CGRectMake(MainW/2-25, 30, 50, 50)];
        _headView.layer.cornerRadius=25;
        _headView.layer.masksToBounds=YES;
        
    }
    return _headView;
    
}
-(UILabel *)IDLab
{
    if (!_IDLab) {
        _IDLab =[[ZJInsertLab alloc]initWithFrame:CGRectMake(0, 110, MainW, 60)];
        _IDLab.backgroundColor=[UIColor whiteColor];
        
    }
    return _IDLab;
    
}

-(UILabel *)pswLab
{
    if (!_pswLab) {
        _pswLab =[[ZJInsertLab alloc]initWithFrame:CGRectMake(0, 110+60+2, MainW, 60)];
        _pswLab.backgroundColor=[UIColor whiteColor];
    }
    return _pswLab;
    
}

-(UIImageView *)IDimageView
{
    if (!_IDimageView) {
        _IDimageView=[MYUI creatImageViewFrame:CGRectMake(10, 128, 20, 20) imageName:@"icon_person"];
    }
    return _IDimageView;
}
-(UIImageView *)PSWimageView
{
    if (!_PSWimageView) {
        _PSWimageView=[MYUI creatImageViewFrame:CGRectMake(10, 128+60, 20, 20) imageName:@"icon_password"];
    }
    return _PSWimageView;
}
-(UITextField *)IDTF
{
    if (!_IDTF) {
        _IDTF=[MYUI createTextFieldFrame:CGRectMake(40, 110, MainW-40, 60) backgroundColor:[UIColor clearColor] placeholder:MyString(@"请输入账号") clearsOnBeginEditing:NO];
        _IDTF.keyboardType=UIKeyboardTypeNumberPad;
    }
    return _IDTF;
    
}
-(UITextField *)pswTF
{
    if (!_pswTF) {
       
        _pswTF=[MYUI createTextFieldFrame:CGRectMake(40, 110+60+2, MainW-40-40, 60)  backgroundColor:[UIColor clearColor] secureTextEntry:YES placeholder:MyString(@"请输入密码") clearsOnBeginEditing:NO];
        
    }
    return _pswTF;
    
}
-(UIView *)view{
    if (!_view) {
        _view=[MYUI createViewFrame:CGRectMake(0, 110+60+2+62, MainW, 60) backgroundColor:[UIColor whiteColor]];
    }
    return _view;
}
-(UIImageView *)imag{
    if (!_imag) {
        _imag=[MYUI creatImageViewFrame:CGRectMake(10, 20, 20, 20) image:[UIImage imageNamed:@"icon_identify"]];
    }
    return _imag;
}
-(UIImageView *)CheckImg{
    if (!_CheckImg) {
        _CheckImg=[MYUI creatImageViewFrame:CGRectMake(MainW-90, 0, 90, 60) image:[UIImage imageNamed:@"icon_identify"]];
    }
    return _CheckImg;
}
-(UIButton *)CheckBtn{
    if (!_CheckBtn) {
        _CheckBtn=[MYUI creatButtonFrame:CGRectMake(MainW-90, 0, 90, 60) backgroundColor:[UIColor clearColor] setTitle:nil setTitleColor:nil];
    }
    return _CheckBtn;
}

-(UITextField *)CheckNum
{
    if (!_CheckNum) {
        
        _CheckNum=[MYUI createTextFieldFrame:CGRectMake(40, 0, MainW-160, 60)  backgroundColor:[UIColor clearColor] secureTextEntry:YES placeholder:MyString(@"请输入验证码") clearsOnBeginEditing:NO];
        _CheckNum.secureTextEntry =NO;
        _CheckNum.clearButtonMode=UITextFieldViewModeNever;
        
    }
    return _CheckNum;
    
}

//10, 170+2+90, MainW-20, 98/2
-(UIButton *)logBtn{
    if (!_logBtn) {

        _logBtn=[MYUI creatButtonFrame:CGRectMake(0,0,0,0) backgroundColor:button_gray_Color setTitle:MyString(@"登录") setTitleColor:Btn_TxTGray_Color ];
        _logBtn.layer.cornerRadius=5;
        _logBtn.layer.masksToBounds=YES;
        _logBtn.titleLabel.font=FontAndStyle15;
        
        
    }
    return _logBtn;
}
//线条
-(UILabel *)lineLab
{
    if (!_lineLab) {
        _lineLab=[[UILabel alloc]initWithFrame:CGRectMake(10, 726/2, MainW-20, 0.5)];
        _lineLab.backgroundColor=RGB(153, 153, 153);
        
    }
    return _lineLab;
    
}
-(UIButton *)findpswBtn
{
    if (!_findpswBtn) {
        
        _findpswBtn=[MYUI creatButtonFrame:CGRectMake(MainW-70, 170+2+90+49+10, 80, 20) backgroundColor:[UIColor clearColor] setTitle:MyString(@"找回密码")  setTitleColor:[UIColor colorWithRed:228.0/255.0 green:82.0/255.0 blue:29.0/255.0 alpha:1] ];
        _findpswBtn.titleLabel.font=[UIFont fontWithName:@"PingFangSC-Regular" size:12];
        
    }
    return _findpswBtn;
}

-(UILabel *)LogonlineLab
{
    if (!_LogonlineLab) {
        _LogonlineLab=[[UILabel alloc]initWithFrame:CGRectMake(MainW/2-112/2, 726/2-7.5, 112, 15)];
        _LogonlineLab.backgroundColor=RGB(246, 246, 246);
        _LogonlineLab.text=MyString(@"或使用以下方式登陆");
        _LogonlineLab.font=[UIFont fontWithName:@"PingFangSC-Regular" size:10];
        _LogonlineLab.textColor=RGB(102, 102, 102);
        _LogonlineLab.textAlignment=YES;
    
    }
    return _LogonlineLab;
    
    
}

//微信btn
-(UIButton *)weiChatBtn
{
    if (!_weiChatBtn) {
        _weiChatBtn=[MYUI creatButtonFrame:CGRectMake(MainW/2-55, 726/2+20, 46, 46) setBackgroundImage:[UIImage imageNamed:@"icon_wechat"]  setTitle:MyString(@"微信")  setTitleColor:[UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1] ];
        _weiChatBtn.titleLabel.font=[UIFont fontWithName:@"PingFangSC-Regular" size:12];
        
      

    }
    return _weiChatBtn;
}
//qqbtn
-(UIButton *)qqBtn
{
    if (!_qqBtn) {
          _qqBtn=[MYUI creatButtonFrame:CGRectMake(MainW/2+10, 726/2+20, 46, 46)setBackgroundImage:[UIImage imageNamed:@"icon_qq"] setTitle:@"QQ"  setTitleColor:[UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1] ];
         _qqBtn.titleLabel.font=[UIFont fontWithName:@"PingFangSC-Regular" size:12];
//        _qqBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
//        [_qqBtn setTitleEdgeInsets:UIEdgeInsetsMake(80,-_qqBtn.imageView.frame.size.width, 0.0,0.0)];//文字距离上边框的距离增加imageView的高度，距离左边框减少imageView的宽度，距离下边框和右边框距离不变
//        [_qqBtn setImageEdgeInsets:UIEdgeInsetsMake(0.0, 0.0,0.0, -_qqBtn.titleLabel.bounds.size.width)];//图片距离右边框距离减少图片的宽度，其它不边
        
        
     
    }
    return _qqBtn;
}





@end
